package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleHomeController {
    @Resource
    private ApArticleService apArticleService;

    /**
     * 加载首页文章列表
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){

        return apArticleService.load(dto, (short) 1);
    }


    /**
     * 加载更多
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto){

        return apArticleService.load(dto, (short) 1);
    }


    /**
     * 加载最新
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto){

        return apArticleService.load(dto, (short) 2);
    }
    /**
     * 根据作者ID获取文章列表
     * @param authorId
     * @return
     */
    @GetMapping("/listByAuthor/{authorId}")
    public ResponseResult getArticleByAuthorId(@PathVariable Integer authorId){
        return apArticleService.getApUserInfo(authorId);
    }

}
